package pheeraphonglek.testing;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import com.google.gson.Gson;

import pheeraphonglek.dictionary.transform.Constants;
import pheeraphonglek.dictionary.transform.model.Dictionary;
import pheeraphonglek.dictionary.transform.model.TransformDictionary;
import pheeraphonglek.dictionary.transform.model.Vocabulary;
import pheeraphonglek.dictionary.utils.Transform;

public class MTest {

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {

		String word = args[0];
		
		String strUrl = String.format("http://127.0.0.1:8888/LongdoTransform?word=%s",word);
		URL url = new URL(strUrl);
		URLConnection yc = url.openConnection();
		BufferedReader in = new BufferedReader(new InputStreamReader(
				yc.getInputStream(),"UTF-8"));
		String inputLine;
		StringBuilder data = new StringBuilder();

		while ((inputLine = in.readLine()) != null) {
			data.append(inputLine);
		}
		in.close();
		
		String json = data.toString();
		Gson gson = new Gson();
		
		System.out.println("========================================================================");
		System.out.println("==============================FROMJSON==================================");
		System.out.println("========================================================================");
		TransformDictionary ts = gson.fromJson(json, TransformDictionary.class);
		for(Dictionary d: ts.getDictionary())
		{
			System.out.println("Dictionay: " + d.getName());
			for(Vocabulary v: d.getVocabularyList()){
				System.out.print(v.getVocap());
				System.out.println("\t" + v.getMean());
			}
			System.out.println();			
		}
		Transform tf = new Transform();
		TransformDictionary tDictionary = tf.findWord(word);
		
		System.out.println("========================================================================");
		System.out.println("==============================FROMLONG==================================");
		System.out.println("========================================================================");
		for(Dictionary d: tDictionary.getDictionary())
		{
			System.out.println("Dictionay: " + d.getName());
			for(Vocabulary v: d.getVocabularyList()){
				System.out.print(v.getVocap());
				System.out.println("\t" + v.getMean());
			}
			System.out.println();			
		}
		
		//String json  = "";
		//Gson gson = new Gson();
//		json = gson.toJson(tDictionary);
//		
//		TransformDictionary t2 = gson.fromJson(json, TransformDictionary.class);
//		
//		for(Dictionary d: t2.getDictionary())
//		{
//			System.out.println("Dictionay: " + d.getName());
//			for(Vocabulary v: d.getVocabularyList()){
//				System.out.print(v.getVocap());
//				System.out.println("\t" + v.getMean());
//			}
//			System.out.println();			
//		}
		
		

	}

}
